<?php global $woo_options; ?>
<?php
	remove_filter( 'posts_orderby', 'woo_post_order_dir', 99 );
	
	/*----------------------------------------------------------------------
	  Get and process the numposts fields from the woo options panel.
	  Both are processed the same way, so run them in a loop to avoid
	  re-coding the same thing twice.
	
	  Each will be available as a variable, eg $woo_numposts_topbar.
	----------------------------------------------------------------------*/
	
	$numpost_fields = array( 'woo_numposts_topbar', 'woo_numposts_dropdown' );
	
	foreach ( $numpost_fields as $f ) {
	
		${$f} = intval( $woo_options[$f] );
		
		if ( ${$f} <= 0 ) {
		
			${$f} = 20;
		
		} // End IF Statement
	
	} // End FOREACH Loop
	
	// Get total post count.
	$posts = query_posts('posts_per_page=-1');
	$total_posts = count( $posts );
	
	wp_reset_query();
?>
		<div id="chapters">
			<div id="horizontal">
				<h2 class="title"><?php _e('Chapters','woothemes'); ?></h2>
				
				<?php if ( is_home() ) { ?>
				
					<?php if ($woo_options['woo_post_order'] == "ASC") { $max = 1; } else { query_posts('posts_per_page=' . $woo_numposts_topbar . '&orderby=date&order=asc'); ?>
					<?php if (have_posts()) : $max = 0; while (have_posts()) : the_post(); $max++; endwhile; endif; } ?>	
					
					<ul>
					<?php query_posts('posts_per_page=' . $woo_numposts_topbar . '&orderby=date&order=asc'); ?>
					<?php if (have_posts()) : $count = 1; ?>
	        		<?php while (have_posts()) : the_post(); ?>
	        		
						<li <?php if ( $count == ( $max ) ) { ?>class="selected"<?php } ?> title="<?php the_title(); ?>">
							<a href="<?php the_permalink() ?>">
								<span><?php echo $count; ?></span>
							</a>
						</li>        		
	        		
	        		<?php $count++; endwhile; endif; ?>
	        		
	        		</ul>
				
				<?php } else { ?>
					
					<ul>
					<?php query_posts('posts_per_page=' . $woo_numposts_topbar . '&orderby=date&order=asc'); ?>
					<?php if (have_posts()) : $count = 1; ?>
	        		<?php while (have_posts()) : the_post(); ?>
	        		
						<li <?php if ( $GLOBALS['selected'] == get_the_title($post->ID) ) { ?>class="selected"<?php } ?> title="<?php the_title(); ?>">
							<a href="<?php the_permalink() ?>">
								<span><?php echo $count; ?></span>
							</a>
						</li>        		
	        		
	        		<?php $count++; endwhile; endif; ?>
	        		</ul>
				
				<?php } ?>
				<!--- menu--->
				<div style="position: absolute; left: 400px; top: 0px" id="mmenu"> 
				<ul >    		
						<li title="Trang chủ">
							<a href="http://trieuxuan.info/demo/">
								<span>Trang chủ</span>
							</a>
						</li>      
						
	        		<li title="Tin tức">
							<a href="http://trieuxuan.info/demo/index.php/category/tintuc/">
								<span>Tin tức</span>
							</a>
						</li>  
<li  title="Sách mới">
							<a href="http://trieuxuan.info/demo/index.php/category/sachmoi/">
								<span>Sách mới</span>
							</a>
						</li>  
						
						<li  title="Tác giả">
							<a href="http://trieuxuan.info/demo/index.php/category/tacgia/">
								<span>Tác giả</span>
							</a>
						</li> 						
	    <li  title="Hình ảnh">
							<a href="http://trieuxuan.info/demo/index.php/album/">
								<span>Album</span>
							</a>
						</li>  
	        		
	        	</ul>
				</div>
				<!--- end menu--->
				
			</div>
			<hr />
			<div id="vertical">
				<ul>
				<?php query_posts('posts_per_page=' . $woo_numposts_dropdown . '&orderby=date&order=asc'); ?>
				<?php if (have_posts()) : $count = 1; ?>
        		<?php while (have_posts()) : the_post(); ?>
        		
					<li>
						<a href="<?php the_permalink() ?>">
							<span><?php echo $count; ?></span>
							<strong><?php the_title(); ?></strong>
							<small><?php echo get_post_meta($post->ID, "caption", $single = true); ?></small>
						</a>
					</li>        		
        		
        		<?php $count++; ?>
        		
        		<?php endwhile; endif; ?>
        		<?php
        			if ( $woo_numposts_dropdown < $total_posts ) {
        			
        			// Determine the URL to use.
        			$postspage_url = site_url();
        			
        			if ( get_option('show_on_front') == 'page' ) {
        			
        				$postspage_url = get_permalink( get_option('page_for_posts') );
        			
        			} // End IF Statement
        			
        			$postspage_url = apply_filters( 'woo_chapters_moreposts_url', $postspage_url );
        		?>
        			<li><a href="<?php echo $postspage_url; ?>"><strong><?php _e( 'More Posts', 'woothemes' ); ?></strong></a></li>
        		<?php
        			} // End IF Statement
        		?>
        		</ul>
			</div>
		</div>
		
		<div class="fix"></div>
		
		</div><!-- /#wrapper-inner -->
		</div><!-- /#wrapper -->
		
		<div id="footer">
			
			<?php if ( woo_active_sidebar('footer-1') ||
			   woo_active_sidebar('footer-2') || 
			   woo_active_sidebar('footer-3') || 
			   woo_active_sidebar('footer-4') ) : ?>
				<div id="footer-widgets" class="col-full">
				
				    <div class="block">
    			    	<?php woo_sidebar('footer-1'); ?>    
				    </div>
				    <div class="block">
    			    	<?php woo_sidebar('footer-2'); ?>    
				    </div>
				    <div class="block">
    			    	<?php woo_sidebar('footer-3'); ?>    
				    </div>
				    <div class="block">
    			    	<?php woo_sidebar('footer-4'); ?>    
				    </div>
				    <div class="fix"></div>
				
				</div><!-- /#footer-widgets  -->
    		<?php endif; ?>
			
			<div class="footer-inside">
		
				<div id="copyright" class="col-left">
				
					<?php if($woo_options['woo_footer_left'] == 'true'){
						echo stripslashes($woo_options['woo_footer_left_text']);	
					} else { ?>
						<p>&copy; <?php echo date('Y'); ?> <?php bloginfo(); ?>. <?php _e('All Rights Reserved.', 'woothemes') ?></p>
					<?php } ?>
				</div>
				
				<div id="credit" class="col-right">
        			<?php if($woo_options['woo_footer_right'] == 'true'){
						echo stripslashes($woo_options['woo_footer_right_text']);
       				} else { ?>
						<p><?php _e('Powered by', 'woothemes') ?> <a href="http://www.wordpress.org">WordPress</a>. <?php _e('Designed by', 'woothemes') ?> <a href="<?php $aff = $woo_options['woo_footer_aff_link']; if(!empty($aff)) { echo $aff; } else { echo 'http://www.woothemes.com'; } ?>"><img src="<?php bloginfo('template_directory'); ?>/images/woothemes.png" width="74" height="19" alt="Woo Themes" /></a></p>
					<?php } ?>
				</div>
			
			</div><!-- /#footer-inside -->
			
			<div class="fix"></div>
			
		</div>

<?php wp_footer(); ?>
<?php woo_foot(); ?>
</body>
</html>